package com.qfedu.wfx.manager.Controller;

import com.qfedu.wfx.manager.user.po.WxbCustomer;
import com.qfedu.wfx.manager.user.service.IMerchantService;
import com.qfedu.wfx.manager.vo.JsonResultVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/merchant")
public class MerchantController {
    @Autowired
    private IMerchantService merchantService;
    @RequestMapping("/list")
    @RequiresPermissions({"商户信息管理"})
    public String queryMerchantInfoList(Model model){
        List<WxbCustomer> wxbCustomers = merchantService.queryMerchantInfo();
        model.addAttribute("wxbCustomers",wxbCustomers);
        return "merchant-list";
    }
    @RequestMapping("save")
    @ResponseBody
    public JsonResultVO saveMerchantInfo(WxbCustomer wxbCustomer){
        JsonResultVO jsonResultVO = new JsonResultVO();
        try {
            merchantService.saveMerchantInfo(wxbCustomer);
            jsonResultVO.setCode(1);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResultVO.setCode(0);
        }
        return jsonResultVO;
    }
}
